﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlTypes;
using System.Linq;
using System.Text;


namespace nadModel.pad
{
    public partial class WhereUsedEntityProcess : AbstractEntityProcess
    {

        public override AbstractEntity[] PackEntity(object obj)
        {
            //pack entries
            List<WhereUsedEntity> entryList = new List<WhereUsedEntity>();

            WhereUsedEntity entry;
            try
            {
                DataTable dt = (DataTable)obj;
                if (dt == null)
                {
                    return null;
                }

                foreach (DataRow item in dt.Rows)
                {
                    entry = new WhereUsedEntity();
                    entry.IUM = item[WhereUsedEntity.I_U_M].ToString();
                    entry.MtlPartDesc = item[WhereUsedEntity.MTLPARTDESC].ToString();
                    entry.MtlPartnum = item[WhereUsedEntity.MTLPARTNUM].ToString();
                    entry.PartDesc = item[WhereUsedEntity.PARTDESC].ToString();
                    entry.PartNum = item[WhereUsedEntity.PARTNUM].ToString();
                    entry.QtyPer = decimal.Parse(item[WhereUsedEntity.QTYPER].ToString());
                    entry.RevisionNum = item[WhereUsedEntity.REVISIONNUM].ToString();
                    entryList.Add(entry);
                }
            }
            catch (Exception ex)
            {
                Log("ERROR: error packing entity", LogLevel.FATAL);
                Log(ex.ToString(), LogLevel.FATAL);
                throw ex;
            }
            return (AbstractEntity[])entryList.ToArray();

        }
    }
}
